package sample.stormax.pres.news;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import sample.stormax.pres.news.beans.Data;

public class NewsDetailActivity extends AppCompatActivity {

    private ProgressDialog progressDialog;

    @BindView(R.id.web_news)
    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        Bundle bundle= intent.getExtras();
        Data data = (Data) bundle.get("data");

        initDialog();

        //开启对Js的支持
        webView.getSettings().getJavaScriptEnabled();

        //增加对用户的加载提示和防止外部浏览器的跳转
        webView.setWebViewClient(new WebViewClient(){
            //开始加载一个网页的回调
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                if(!progressDialog.isShowing())
                    progressDialog.show();
            }

            //结束加载一个网页的回调
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (progressDialog.isShowing())
                    progressDialog.dismiss();
            }
        });
        webView.loadUrl(data.getUrl());
    }

    private void initDialog() {
        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("玩命加载中。。。。");
    }
}
